package nz.co.doherty.gwtpbreadcrumbs.server.handler.customer;

import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.customer.CustomerRetrieveAction;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.customer.CustomerRetrieveResult;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.philbeaudoin.gwtp.dispatch.server.ExecutionContext;
import com.philbeaudoin.gwtp.dispatch.server.actionHandler.ActionHandler;
import com.philbeaudoin.gwtp.dispatch.shared.ActionException;

public class CustomerRetrieveHandler implements ActionHandler<CustomerRetrieveAction, CustomerRetrieveResult> {

	@Override
	public CustomerRetrieveResult execute(CustomerRetrieveAction action,
			ExecutionContext context) throws ActionException {

		Objectify ofy = ObjectifyService.begin();
		return new CustomerRetrieveResult(ofy.get(action.getCustomerKey()));

	}

	@Override
	public void undo(CustomerRetrieveAction action,
			CustomerRetrieveResult result, ExecutionContext context)
			throws ActionException {
		// TODO Auto-generated method stub

	}

	@Override
	public Class<CustomerRetrieveAction> getActionType() {
		return CustomerRetrieveAction.class;
	}

}
